package com.example.messageservice;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.widget.Toast;

/**
 * Created by xuxingcan on 16-7-31.
 */
public class MessageService extends Service {
    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {
        WID.getWid(getApplicationContext());
        FileUtil.getInstance().writeLog("MessageService onCreate\n\n\n");
        super.onCreate();
        Intent intent1 = new Intent("LOCATION");
        PendingIntent pi = PendingIntent.getBroadcast(getApplicationContext(), 1, intent1, 0);
        AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
        am.setRepeating(AlarmManager.RTC_WAKEUP,
                System.currentTimeMillis() + 2 * 60 * 1000, 2 * 60 * 1000, pi);
        LocationUtil.getLocation(getApplicationContext());
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        return START_STICKY;
//        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void onDestroy() {
        Intent intent = new Intent("com.dbjtech.waiqin.destroy");
        sendBroadcast(intent);
        super.onDestroy();
    }
}
